//
//  PaperItemModel.swift
//  Exam-iOS
//
//  Created by 李胜锋 on 2018/3/6.
//  Copyright © 2018年 李胜锋. All rights reserved.
//

import Foundation
import ObjectMapper

///题目类型
enum PaperItemType: Int {
    //----------选择型题
    ///单选题
    case radio = 1
    ///多选题
    case multiSelect = 2
    ///判断题
    case trueOrFalse = 3
    
    //---------------主观题
    ///简答题
    case shortAnswer = 4
    ///案例分析题
//    case caseAnalysis = 4
    
    ///综合分析题
    case analysis = 5
    
    ///公文筐测验
    case in_trayTest = 6
    
    ///计算题
    case calculation = 7
    
    
    ///是否是选择提醒
    func isSelect() -> Bool {
        if self == .radio ||
            self == .multiSelect ||
            self == .trueOrFalse {
            return true
        }
        
        return false
    }
    
    ///是否是主观题
    func isSubjective() -> Bool {
        if self == .analysis ||
            self == .shortAnswer ||
            self == .in_trayTest ||
            self == .calculation {
            return true
        }
        return false
    }
}

///题目模式
enum PaperItemMethod: Int {

    ///考试
    case exam = 1
    
    ///解析
    case analysis
    ///自评分
    case selfReported
}

///题目选项
class PaperItemOptionModel: Mappable {
    var desc: String?
    var id: String?
    
    func mapping(map: Map) {
        desc <- map["desc"]
        id <- map["id"]
    }
    required init?(map :Map) { }
}

enum PaperItemOptionStatus: Int{
    case nomal  //默认状态
    case choise //选中状态
}

enum PaperUserLike: Int {
    case `default` = 0
    case like = 1
}


///答案结果
enum PaperItemAnswerResult: Int {
    //未判断结果
    case none = 0
    //正确
    case correct = 1
    ///错误
    case error = 2
    
    ///主观题用户自评分
    case selfReported = 3
}

///题目
class PaperItemModel: Mappable {
    ///难度
    var difficulty: Int?
    ///id
    var id: Int?
    ///当前题目在试卷中的索引位置
    var index: Int?
    ///问题描述
    var quest: String?
    ///题目类型
    var type: PaperItemType?
    ///试题分值
    var score: Double?
    ///选项
    var options: [PaperItemOptionModel]?
    ///收藏
    var userLike: PaperUserLike = .default
    ///答案
    var answer: String?
    ///试题解析
    var analysis: String?
    
    
    ///回答结果
    var userAnswerResult: PaperItemAnswerResult?
    ///用户得分
    var userScore: Double?
    //选择题存储答案选项的id
    //简答题、分析题存储用户输入的答案
    var userAnswer: String?
    
    func mapping(map: Map) {
        difficulty <- map["difficulty"]
        id   <- map["itemId"]
        index   <- map["itemIndex"]
        quest  <- map["itemQuest"]
        type  <- map["itemType"]
        options <- map["options"]
        score <- map["score"]
        answer <- map["answer"]
        analysis <- map["analysis"]
        userLike <- map["userLike"]
        userAnswer <- map["userAnswer"]
        userAnswerResult <- map["userAnswerResult"]
        userScore <- map["userScore"]
    }
    
    required init?(map :Map) {
    }
    
    var method = PaperItemMethod.exam
}
